package com.s59.rabc.shrio;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.s59.rabc.commen.LoginException;
import com.s59.rabc.entity.Menu;
import com.s59.rabc.entity.Role;
import com.s59.rabc.entity.User;
import com.s59.rabc.service.IMenuService;
import com.s59.rabc.service.IRoleService;
import com.s59.rabc.service.IUserService;
import com.s59.rabc.service.impl.PermssionService;
//import org.apache.shiro.authc.AuthenticationException;
//import org.apache.shiro.authc.AuthenticationInfo;
//import org.apache.shiro.authc.AuthenticationToken;
//import org.apache.shiro.authc.SimpleAuthenticationInfo;
//import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
//import org.apache.shiro.authz.AuthorizationInfo;
//import org.apache.shiro.authz.SimpleAuthorizationInfo;
//import org.apache.shiro.realm.AuthorizingRealm;
//import org.apache.shiro.subject.PrincipalCollection;
//import org.apache.shiro.util.ByteSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class ScrimRealm
//        extends AuthorizingRealm
{
//    @Autowired
//    private IUserService userService;
//    @Autowired
//    private PermssionService permssionService;
//
//    public ScrimRealm(HashedCredentialsMatcher hashedCredentialsMatcher) {
//        super(hashedCredentialsMatcher);
//    }
//
//    /**
//     * 鉴权时调用
//     * @param principalCollection
//     * @return
//     */
//    @Override
//    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
//        User user = (User) principalCollection.getPrimaryPrincipal();
//        SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
//        simpleAuthorizationInfo.addRoles(permssionService.getRoleKey(user.getUserName()));
//        simpleAuthorizationInfo.addStringPermissions(permssionService.getParms(user.getUserName()));
//        return simpleAuthorizationInfo;
//    }
//
//    /**
//     * 登录时调用
//     * @param authenticationToken
//     * @return
//     * @throws AuthenticationException
//     */
//    @Override
//    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
//        String username = (String) authenticationToken.getPrincipal();
//        User user = userService.getOne(Wrappers.lambdaQuery(User.class).eq(User::getUserName,username));
//        if (user != null) {
//            return new SimpleAuthenticationInfo(user,user.getPassword(), ByteSource.Util.bytes(user.getSalt()),getName());
//        }
//        return null;
//    }
}
